
$(function() {
	Tip.emp('员工');

	// validate signup form on keyup and submit
	var validator = $("#form_add").validate({
		rules: {
			ip_new: {
				required: false,
				remote: "emp.php?do=Mac.ajax_exist"
			},
			name: {
				required: true,
				minlength:2
			},
			address: "required"
		},
		messages: {
			ip_new: {
				required: "请输入新地址",
				remote: jQuery.format("{0} 已经使用")
			},
			name: {
				required: "请输入简称",
				minlength: jQuery.format("请最少输入 {0} 个字符")
			},
			address: "请输入地址"
		},
		errorPlacement: function(label, element) {
			if (/^birthdate/.test(element[0].name)) {
				label.insertAfter("#birthdateYear");
			} else {
				label.insertAfter(element);
			}
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
	
	$("input[id='ip']:visible").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: 'emp.php?do=Mac.ajax_ip',
				dataType: "json",
				data: {
					featureClass: "P",
					style: "full",
					maxRows: 12,
					q: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label: item.ip + " [" + item.emp_t + ", " + item.status_t + "]",
							value: item.ip + ":" + item.emp_t
						}
					}));
				}
			});
		},
		
		minLength: 1
	});
});